package org.sunsys.qa.txnhandler;

import org.sunsys.qa.user.User;
import org.sunsys.qa.user.UserRegistrationDto;
import org.sunsys.qa.user.dao.UserDao;
import org.sunsys.qa.user.dao.UserDaoImpl;
import org.sunsys.qa.user.exceptions.UserIdAlreadyExistedException;
import org.sunsys.qa.user.exceptions.UserValidationException;

public class UserTxnsHandler {

	private UserDao userDao = new UserDaoImpl();
	
	public UserTxnsHandler() {
	}
	
	/**
	 * 
	 * @param registrationDto UserRegistrationDto
	 * @throws UserIdAlreadyExistedException
	 */
	public void registerUser(UserRegistrationDto registrationDto) throws UserIdAlreadyExistedException {
		/*
		 * 1.	Use DAO class to insert the record
		 * 2.	if inserted successfully 
		 * 			2.1 	set the UserRegistrationResponse status as Success
		 * 3.	else 
		 * 			3.2		set the UserRegistrationResponse status as Failed, and cause as message
		 */
		
		//TODO have to handle the DAO related exception(s)
		userDao.registerUser(registrationDto);
	}
	
	/**
	 * returns true, if user exists, else false
	 * @param user
	 * @return boolean
	 * @throws UserValidationException 
	 */
	public boolean doesUserExists(User user) throws UserValidationException {

		/* validate the user using User Dao */
		return userDao.doesUserExists(user);
		
	}
}
